var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    noShow: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    that.getList()
  },
  jumpCard(e) {
    console.log(e, 'cardfee')
    wx.navigateTo({
      url: '../CardDetails/CardDetails?isUser=' + this.data.isUser + '&card=' + e.currentTarget.dataset.card + '&address=' + e.currentTarget.dataset.address + '&cardfee=' + e.currentTarget.dataset.cardfee + '&hotline=' + e.currentTarget.dataset.hotline + '&balance=' + e.currentTarget.dataset.balance + '&phone=' + e.currentTarget.dataset.phone +'&canViewUseRecord=' + this.data.canViewUseRecord + '&memo=' + e.currentTarget.dataset.memo + '&userName=' + e.currentTarget.dataset.username + '&cardOwner=' + e.currentTarget.dataset.cardowner,
    })
  },
  gofund(e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.hotline,
    })
  },
  gotoCardDetail(e) {
    console.log(e)
    wx.navigateTo({
      url: '../cardDetail/cardDetail?isUser=' + this.data.isUser + '&card=' + e.currentTarget.dataset.card + '&address=' + e.currentTarget.dataset.address + '&cardfee=' + e.currentTarget.dataset.cardfee + '&hotline=' + e.currentTarget.dataset.hotline + '&balance=' + e.currentTarget.dataset.balance,
    })
  },
  gotorefund(e) {
    wx.navigateTo({
      url: '../refund/refund?isUser=' + this.data.isUser + '&card=' + e.currentTarget.dataset.card + '&address=' + e.currentTarget.dataset.address + '&cardfee=' + e.currentTarget.dataset.cardfee + '&hotline=' + e.currentTarget.dataset.hotline + '&balance=' + e.currentTarget.dataset.balance,
    })
  },
  getList() {
    var that = this
    wx.showLoading({
      title: '加载中',
    })
    app.executeRequest(function (header) {
      wx.request({
        url: app.BASE_URL + '/hospitalized/getIcardInfo',
        header,
        success: (res) => {
          getApp().hideLoading()
          console.log(res)
          if(res.data.result == 0){
            that.setData({
              dataList: res.data.data.infos,
              isUser: res.data.data.isUser,
              canViewUseRecord: res.data.data.canViewUseRecord ? res.data.data.canViewUseRecord : '',
              noShow: true,
              canShow:false
            })
          }else{
            if(res.statusCode == 404){
              that.setData({
                canShow:true
              })
            }
          }

        },
        fail:(err)=>{
          console.log(err)
        }
      })

    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})